package priv.xp.androidexample

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import priv.xp.androidexample.adapter.GirlAdapter
import priv.xp.androidexample.databinding.FragmentGirlBinding
import priv.xp.androidexample.viewmodel.GirlViewModel

@Route(path = "/girl/fragment")
class GirlFragment : Fragment() {
    private val viewMode: GirlViewModel by lazy {
        ViewModelProvider(this)[GirlViewModel::class.java]
    }
    private lateinit var binding: FragmentGirlBinding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentGirlBinding.inflate(inflater, container, false)

        val girlAdapter = GirlAdapter()
        viewMode.girls.observe(viewLifecycleOwner, {
            girlAdapter.submitList(it)
        })
        binding.listGirl.layoutManager = LinearLayoutManager(this.context)
        binding.listGirl.hasFixedSize()
        binding.listGirl.adapter = girlAdapter

        return binding.root
    }

}
